<?php
/**
 * 分类管理
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-6-17
 * Time: 下午2:37
 */
namespace app\modules\cn\controllers;

use app\libs\Method;
use app\libs\IeltsController;
use app\modules\cn\models\Info;
use app\modules\content\models\Active;
use app\modules\content\models\Banner;
use app\modules\content\models\Book;
use app\modules\content\models\Classes;
use app\modules\content\models\Recommend;
use app\modules\content\models\Teachers;
use app\modules\cn\models\CaseList;

class IndexController extends IeltsController
{
    public $enableCsrfValidation = false;
    public $layout = 'cn';

    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        $detect = new \Mobile_Detect();
        if ($detect->isMobile()){
            $this->redirect('http://m.thinkuprep.com');
        }
    }

    /**
     * 分类列表展示
     * @return string
     * @Obelisk
     */
    public function actionIndex()
    {
        // //公开课
        // $class[1] = Active::find()->asArray()->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[1] = Classes::find()->asArray()->where('cate=1')->orderBy('viewCount desc')->all();
        // //小班课
        // $class[2] = Classes::find()->asArray()->where('cate=2')->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[2] = Classes::find()->asArray()->where('cate=2')->orderBy('viewCount desc')->all();
        // //单项课
        // $class[3] = Classes::find()->asArray()->where('cate=3')->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[3] = Classes::find()->asArray()->where('cate=3')->orderBy('viewCount desc')->all();
        // //录播课
        // $class[4] = Classes::find()->asArray()->where('cate=4')->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[4] = Classes::find()->asArray()->where('cate=4')->orderBy('viewCount desc')->all();
        // //直播课
        // $class[5] = Classes::find()->asArray()->where('cate=5')->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[5] = Classes::find()->asArray()->where('cate=5')->orderBy('viewCount desc')->all();
        // //1对1
        // $class[6] = Classes::find()->asArray()->where('cate=6')->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[6] = Classes::find()->asArray()->where('cate=6')->orderBy('viewCount desc')->all();
        // //面授课/封闭班
        // $class[7] = Classes::find()->asArray()->where('cate=7')->orderBy('sort asc,id desc')->limit(4)->all();
        // $recommend[7] = Classes::find()->asArray()->where('cate=7')->orderBy('viewCount desc')->all();

        // // 底部推荐阅读选取“干货分享”里阅读量最高的两篇
        // $recommend[8] = Info::find()->asArray()->where('cate=2 and pushTime<='.time())->orderBy('viewCount desc')->limit(2)->all();

        // // 优先置顶，再按阅读量倒序
        // $info[0] = Info::find()->asArray()->where("cate=3 and (pushTime<=" . time() . " or pushTime is null)")->limit(8)->orderBy('sort asc,isTop desc,viewCount desc')->all();//头条
        // $info[1] = Info::find()->asArray()->where("cate=1 and (pushTime<=" . time() . " or pushTime is null)")->limit(8)->orderBy('sort asc,isTop desc,viewCount desc')->all();//雅思资讯
        // $ad[1] = Banner::find()->asArray()->limit(1)->where("cate=2")->orderBy('id desc')->one();
        // $ad[2] = Banner::find()->asArray()->limit(1)->where("cate=3")->orderBy('id desc')->one();
        
        // 顶部banner
        $banner = Banner::find()->asArray()->limit(5)->where("cate=1 and type=1")->orderBy('sort asc,id desc')->all();
        // 名师团队
        $teacher = Teachers::find()->where("isTop=1")->asArray()->limit(6)->orderBy('sort asc,id desc')->all();
        // 研发成果
        $book = Book::find()->asArray()->limit(7)->orderBy('sort asc,id desc')->all();
        // 热门活动
        $class[1] = Active::find()->asArray()->orderBy('sort asc,id desc')->limit(4)->all();
        // 雅思课程
        $class[2] = Classes::find()->where("isTop=1")->asArray()->limit(3)->orderBy('sort asc,id desc')->all();
        // 高分案例
        $case = CaseList::find()->limit(6)->orderBy('sort asc,id desc')->asArray()->all();

        $this->title = '申友雅思—专注雅思培训-雅思在线课程-雅思考试';
        $this->keywords = '雅思,雅思培训,雅思考试,雅思在线培训班,英语口语';
        $this->description = '领先的语言培训机构,申友雅思专注雅思培训在线课程,雅思一对一,第一时间为考生提供雅思考试时间,雅思口语,雅思听力,雅思阅读,雅思写作,解决雅思7分难题,是服务全面的雅思培训机构';
        return $this->render('index', [
            'class' => $class, 
            'teacher' => $teacher,
            'book' => $book, 
            'banner' => $banner,
            'case' => $case
        ]);
    }

    /**
     * 雅思指南
     * @yoyo
     */
    public function actionGuide()
    {
        $time = time();
        $recommend = Info::find()->asArray()->where('cate=3 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(4)->all();
        $course = Classes::find()->asArray()->limit(2)->orderBy('viewCount desc')->all();
        $focus = Recommend::find()->asArray()->where('type=2')->orderBy('sort asc,id desc')->limit(6)->all();
        $examInfo = Info::find()->asArray()->where('cate=4 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(3)->all();
        $active = Active::find()->asArray()->orderBy('id desc')->limit(2)->all();
        $this->title = '申友雅思在线_雅思考试指南';
        $this->keywords = '雅思考试,雅思考试简介,雅思考试分类';
        $this->description = '申友雅思帮助考生更好的了解雅思考试的分类，考试的测试结构，考试的模式，满足考生各阶段备考需求，只为雅思提分，申友雅思在线';
        return $this->render('guide',['recommend' => $recommend, 'course' => $course, 'focus' => $focus,'examInfo'=>$examInfo,'active'=>$active]);
    }

    /**
     * 关于我们
     * @yoyo
     */
    public function actionAbout()
    {
        $time = time();
        $recommend = Info::find()->asArray()->where('cate=2 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(4)->all();
        $info = Info::find()->asArray()->where('cate=3 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(4)->all();
        $course = Classes::find()->asArray()->limit(2)->orderBy('viewCount desc')->all();
        $focus = Recommend::find()->asArray()->where('type=2')->orderBy('sort asc,id desc')->limit(6)->all();
        $res = json_decode(Method::post('https://live.thinkwithu.com/api/play/pc-video', ['word'=>'m1o85q72su']), true);
        $video = $res['code'] == 1 ? $res['data']['video'] :'';

        $this->title = '申友雅思在线_关于申友';
        $this->keywords = '申友雅思,雅思培训,在线培训';
        $this->description = '申友雅思在线提供雅思课程培训，最新雅思备考资料，雅思免费公开课，满足考生各阶段备考需求，只为雅思提分，申友雅思在线';
        return $this->render('about',['recommend' => $recommend, 'course' => $course, 'focus' => $focus,'info'=>$info, 'video'=>$video]);
    }

    /**
     * [action404 404页面]
     * @return [type] [description]
     */
    public function actionNotFound()
    {
        return $this->render('404');
    }



    /**
     * 免责声明
     * @yoyo
     */
    public function actionStatement()
    {
 
        $this->title = '申友雅思在线_关于申友';
        $this->keywords = '申友雅思,雅思培训,在线培训';
        $this->description = '申友雅思在线提供雅思课程培训，最新雅思备考资料，雅思免费公开课，满足考生各阶段备考需求，只为雅思提分，申友雅思在线';
        return $this->render('statement',[ ]);
    }

    /**
     * [actionApp app专题页面]
     * @Author don
     * @Date   2021-11-22
     * @return [type]     [description]
     */
    public function actionApp()
    {
        $this->title = '申友雅思在线_申友雅思app';
        $this->keywords = '雅思app,剑雅真题,雅思词汇,写作批改';
        $this->description = '申友雅思app，雅思口语听力阅读写作高分备考工具，是申友教育出品的专门针对雅思只能备考的app，对剑雅真题进行详细解析，根据你的雅思基础推荐智能做题方案，有针对性的突破，让你学习雅思更轻松。';
        
        return $this->render('app');
    }
}
